<template>
  <div class="box">
    <!-- 头部 -->
    <Top></Top>
    <!-- logo -->
    <div class="logo" style="margin-bottom: 30px">
      <img src="https://yanxuan.nosdn.127.net/static-union/164793255107785e.png" alt="" class="img" />
    </div>
    <!-- 用户盒子 -->
    <div class="user-box">
      <!-- 手机号和验证码 -->
      <div class="user-input">
        <input
          class="a"
          type="text"
          name="phone"
          placeholder="请输入手机号"
          v-model="phone"
          v-validate="{
            required: true,
            regex: /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/,
          }"
        />
        <span class="error-msg">{{ errors.first("phone") }}</span>
      </div>
      <div class="user-input" style="margin-top: 10px">
        <input
          class="a"
          type="text"
          v-model="password"
          name="password"
          placeholder="请输入密码"
          v-validate="{
            required: true,
            regex: /^(?![A-Za-z0-9]+$)(?![a-z0-9#?!@$%^&*-.]+$)(?![A-Za-z#?!@$%^&*-.]+$)(?![A-Z0-9#?!@$%^&*-.]+$)[a-zA-Z0-9#?!@$%^&*-.]{8,16}$/,
          }"
        />
        <span class="error-msg">{{ errors.first("password") }}</span>
      </div>
      <!-- 遇到问题 -->
      <div class="trouble">
        <div class="trou-top">
          <div class="top-left">忘记密码？</div>
          <router-link to="/codelogin">
            <div class="top-right">短信快捷登陆</div>
          </router-link>
        </div>

        <div class="login" @touchend="login">登录</div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="bottom">
      <router-link to="/center">
        <span class="else">其他登录方式</span>
      </router-link>
      <i class="iconfont icon-xiangyoujiantou"></i>
    </div>
  </div>
</template>

<script>
import Top from "../components/top.vue";
export default {
  name: "center",
  components: {
    Top,
  },
  data() {
    return {
      phone: "",
      password: "",
      agree: true,
    };
  },
  methods: {
    async login() {
      // 获取手机号和密码
      const { password, phone } = this;
      // 至少有点逻辑
      if (phone && password) {
        console.log(phone);
        console.log(password);
       
          await this.$store.dispatch("user/login", { phone, password });
          //查看路径是否包含query参数
          // 跳转到首页
          this.$router.push({ path:"/loginsuccess" });
       
      }else{
        alert('账号或密码错误')
      }
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  width: 375px;
  height: 100%;
  background-color: #fff;
  /*头部*/

  /*logo部分*/
  .logo {
    width: 100%;
    height: 45px;
    margin-top: 28px;
    background-color: #fff;
    .img {
      width: 134px;
      height: 45px;
    }
  }
  /*user-box*/
  .user-box {
    width: 335.6px;
    height: 275.5px;
    box-sizing: border-box;
    padding: 10px 0 40px;
    margin-top: 80px;
    margin-left: 20px;
    .user-input {
      position: relative;
      width: 100%;
      height: 45.7px;
      display: flex;
      border-bottom: 1px solid #d9d9d9;
      .a {
        width: 100%;
        height: 100%;
        border: none;
        align-self: center;
      }
      .error-msg {
        display: inline-block;
        width: 200px;
        height: 30px;
        line-height: 30px;
        font-size: 14px;
        color: #dd1a21;
        margin-top: 10px;
      }
      ::placeholder {
        position: absolute;
        top: 12px;
        font-size: 14px;
        line-height: 21px;
        height: 21px;
      }
      .code {
        height: 27px;
        position: relative;
        .btn {
          position: absolute;
          top: 10px;
          left: -90px;
          width: 82px;
          height: 27px;
          background-color: #fff;
          border: 1px solid #000;
          font-size: 14px;
          border-radius: 2px;
        }
      }
    }
    .trouble {
      width: 100%;
      height: 100px;
      .trou-top {
        display: flex;
        justify-content: space-between;
        font-size: 14px;
        margin-top: 24px;
      }
      .login {
        margin-top: 18px;
        width: 100%;
        height: 45.7px;
        background-color: #dd1a21;
        line-height: 45.7px;
        color: white;
        font-size: 14px;
        border-radius: 5px;
      }
      .serve {
        font-size: 12px;
        width: 100%;
        height: 47px;
        display: flex;
        .checked {
          display: inline-block;
          height: 40px;
          width: 20px;
          input {
            width: 16px;
            height: 16px;
            margin-left: -5px;
            margin-top: 6px;
          }
        }
        .agree {
          padding-top: 8px;
          box-sizing: border-box;
          .span {
            margin: 0 5px;
          }
          .rule {
            color: #007aff;
          }
        }
      }
    }
  }
  /*底部部分*/
  .bottom {
    width: 335px;
    height: 30px;
    margin-left: 20px;
    margin-top: 23px;
    .else {
      display: inline-block;
      font-size: 14px;
      height: 100%;
    }
    .iconfont {
      font-size: 14px;
    }
  }
}
</style>
